#include <iostream>

class Student
{
    public:

    //构造函数
    // Student() = default;
    //无参
    Student()
    {
        
        m_age = 100;
        m_num = 10;
        m_name = "yeliang";
    }

    //有参
    Student(int age, const std::string& name)
    {
        
        m_age = age;
        m_num = 10;
        m_name = name;
        std::cout<<"带参构造函数"<<std::endl;
    }

    explicit Student(const std::string& name)
    {
        m_name = name;
    }

     /* 拷贝构造函数 */
    Student(const Student& s)
    {
        std::cout<<"拷贝构造函数"<<std::endl;
        m_age = s.m_age;
        m_name = s.m_name;
    }

    #if 1
    void operator=(const Student& s)
    {
        std::cout<<"复制运算符的重载"<<std::endl;
        m_age = s.m_age;
        m_name = s.m_name;
    }
    #else
    /* =运算符重载函数 */
    Student & operator=(const Student &other)
    {   
        std::cout<<"Student copy Student"<<std::endl;
        this->m_num = other.m_num;
        this->m_age = other.m_age;
        this->m_name = other.m_name;
        return *this;
    }
    #endif
    
    //类内声明
    void SetAge(int age);
    int GetAge();
    void SetName(const std::string& name);
    std::string GetName();

    //析构函数
    ~Student()
    {
        std::cout<<"end"<<std::endl;
    }

    private:
    int m_num;
    int m_age;
    std::string m_name;
};


void Student::SetAge(int age)
{
    m_age = age;
}

int Student::GetAge()
{
    return m_age;
}

void Student::SetName(const std::string &name)
{
    m_name = name;
}

std::string Student::GetName()
{
    return m_name;
}

int main()
{
    #if 0
    Student stu;
    stu.SetAge(1);
    stu.SetName("zhangsan");
        
    cout<<"stu.age:"<<stu.GetAge()<<endl;
    cout<<"stu.name:"<<stu.GetName()<<endl;
    #endif

    Student stu2(3,"lisi1");
    std::cout<<stu2.GetAge()<<std::endl;
    std::cout<<stu2.GetName()<<std::endl;

    Student stu3(stu2);
    std::cout<<stu3.GetName()<<std::endl;
    std::cout<<stu3.GetAge()<<std::endl;

    /* 拷贝构造函数 */
    Student s1 = stu2;
    std::cout<<s1.GetName()<<std::endl;  

    /* 复制运算符的重载 */
    Student s2;//先无参
    s2 = stu2;//重载
    std::cout<<s2.GetAge()<<std::endl;
    return 0;


}